import Router from 'vue-router';

import routeListIndex1 from './index-1.js';
import routeListIndex2 from './index-2.js';

const Routes = routeListIndex1.concat(routeListIndex2);

export default () => {
    const siteName = '垃圾回收管理系统';

    // 页面的 title settings
    const initializeSiteTitle = (to, from) => {
        var title = to.meta.title ? to.meta.title + ' - ' + siteName : '忘了设置页面标题啦 ~~~';
        window.document.title = title;
    };

    // mode: history | hash
    const router = new Router({
        mode: 'hash',
        routes: Routes
    });

    router.beforeEach((to, from, next) => {
        // 设置页面标题
        initializeSiteTitle(to, from);
        // 正常路由到下一步
        next();
    });

    router.afterEach((to, from, next) => {
        // 定位滚动条
        window.scrollTo(0, 0);
    });

    return router;
};
